package com.boot2.core.conf;

import com.boot2.core.constant.UploadUrlConstant;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author zhangweilin
 * @description:全局文件上传基础配置,全自动从配置文件中读取上传基础信息
 * @date 2018/6/23
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "upload")
//@PropertySource("classpath:upload.properties")
@Component
public class UploadUrlConf {

    /**
     * 上传根路径
     */
    private String uploadRoot;

    /**
     * 图片上传路径
     */
    private String imgUpload;

    /**
     * 文件上传根路径
     */
    private String fileUpload;

    /**
     * 文件前缀
     */
    private String endPoint;

//    /**
//     * oss专用配置
//     */
//    private OssProperties ossProperties;

    @PostConstruct
    public void init() {
        //根路径
        UploadUrlConstant.uploadRootDir = uploadRoot;

        UploadUrlConstant.imgUploadDir= UploadUrlConstant.uploadRootDir+imgUpload;
        UploadUrlConstant.imgUrl= "/"+imgUpload;

        UploadUrlConstant.fileUploadDir=UploadUrlConstant.uploadRootDir+ fileUpload;
        UploadUrlConstant.fileUrl = "/" + fileUpload;
    }
}
